﻿using SXT.Party.WomenAndChildrens.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZHDJ.MobileInterface
{
    public partial class InsertWCDoctorLeaveMassageReply : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            WCDoctorLeaveMassageReplyOutParam result = new WCDoctorLeaveMassageReplyOutParam();
            WCDoctorLeaveMassageReplyInParam param = new WCDoctorLeaveMassageReplyInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as WCDoctorLeaveMassageReplyInParam;


                if (string.IsNullOrEmpty(param.user_id) || string.IsNullOrEmpty(param.MassageID) || string.IsNullOrEmpty(param.Content))
                {
                    result.code = "0";
                    result.desc = "用户ID，咨询ID，留言内容不能为空";

                    isFlag = false;
                }

                ///判断是否党员
                if (!InterfaceHelper.IsPartyMember(param.user_id, "true"))
                {
                    result.code = "0";
                    result.desc = "不是党员不能留言。";

                    isFlag = false;
                }

                ///判断咨询是否存在
                if (!InterfaceHelper.IsHaveDoctorMessage(param.MassageID))
                {
                    result.code = "0";
                    result.desc = "咨询ID有误，请确认后再提交。";

                    isFlag = false;
                }
                if (isFlag)
                {

                    if (!InterfaceHelper.UpdateDoctorLeaveMassageReply(param.user_id, param.Content, param.MassageID))
                    {
                        result.code = "0";
                        result.desc = "回复失败，多次出现请联系管理员";
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作不成功！";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-InsertWCDoctorLeaveMassageReply", SerializeHelper.JsonSerializer<WCDoctorLeaveMassageReplyInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<WCDoctorLeaveMassageReplyInParam, WCDoctorLeaveMassageReplyOutParam>();
            else
                SafeProcessRequest<WCDoctorLeaveMassageReplyInParam, WCDoctorLeaveMassageReplyOutParam>();
        }
    }

    #region 请求参数
    public class WCDoctorLeaveMassageReplyInParam
    {
        /// <summary>
        ///	用户ID 必须
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        /// 咨询id 必须
        /// </summary>
        public string MassageID
        { get; set; }

        /// <summary>
        ///	回复内容 必须
        /// </summary>
        public string Content
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class WCDoctorLeaveMassageReplyOutParam
    {
        public WCDoctorLeaveMassageReplyOutParam()
        {
            code = "1";
            desc = "操作成功";
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }
    }
    #endregion
}